package com.example.demo;

import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadPoolExecutor;

public class Address implements Cloneable{
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Address address = (Address) o;
        return Objects.equals(name, address.name);
    }

//    @Override
//    public int hashCode() {
//        return 1;
//    }

    public String name;
    private static volatile Address address;
    public String getName() {
        return name;
    }

    public Address() {
    }
    public static Address getAddress() {
        if (address == null) {
            synchronized (Address.class) {
                if (address==null) {
                    return new Address();
                }
            }
        }
        return address;
    }
    public void setName(String name) {
        this.name = name;
    }

    // 省略构造函数、Getter&Setter方法
    @Override
    public Address clone() {
        try {
            return (Address) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }

    }

    public static void main(String[] args) {
        FutureTask<Integer> futureTask = new FutureTask<>(() -> {
            System.out.println(Thread.currentThread().getName());
//            return 1;
        },222);
        new Thread(futureTask).start();
        System.out.println(Thread.currentThread().getName());
        try {
            System.out.println(futureTask.get());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }
}